﻿#ifndef _FITFK_ACOUSTICS_NCT_MODEL_ADAPTOR_H___
#define _FITFK_ACOUSTICS_NCT_MODEL_ADAPTOR_H___

#include "FITKAcousticsAbstractAdaptor.h"
#include "FITK_Kernel/FITKCore/FITKCoreMacros.h"
#include "FITK_Kernel/FITKAdaptor/FITKIOAdaptorFactory.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbsNCT.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsNCTLayUp.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsNCTPerforated.h"


#include <H5Cpp.h>
namespace IO {
    class FITKHDF5FileTool;
    class FITKAcousticsAbsNCT;
}
namespace Acoustics {
    class FITKAcousticsNCTAbstractLayObj;
    class FITKAcousticsNCTPerforated;
}
namespace IO
{
    class FITKAcousticsHDF5IOAPI FITKAcousticsNCTMgrAdaptor : public FITKAcousticsAbsAdaptor
    {
    public:
        explicit FITKAcousticsNCTMgrAdaptor() = default;
        virtual ~FITKAcousticsNCTMgrAdaptor() = default;

        virtual bool adaptR() override;

        virtual bool adaptW() override;

    private:

        /**
        * @brief 读多重声学包hdf5到数据
        * @param @param[i]  NCTGroup hdf5组别
        * @param @param[i]  mager    声学包管理器
        * @author yangjing (1195810980@qq.com)
        * @date 2025-1-2
        */
        bool readMulitipleNCTs(H5::Group & NCTGroup, Acoustics::FITKAcousticsNCTManager* mager);


        /**
        * @brief 多重声学包数据到hdf5
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  MulitipleNCTs    多重声学包数据
        * @author yangjing (1195810980@qq.com)
        * @date 2025-1-2
        */
        bool writeMulitipleNCTs(H5::Group & NCTGroup, QList<Acoustics::FITKAcousticsAbsNCT*> MulitipleNCTs);



        /**
        * @brief 读用户自定义声学包hdf5到数据
        * @param @param[i]  NCTGroup hdf5组别
        * @param @param[i]  mager    声学包管理器
        * @author yangjing (1195810980@qq.com)
        * @date 2025-1-2
        */
        bool readUserDefTreatments(H5::Group & NCTGroup, Acoustics::FITKAcousticsNCTManager* mager);


        /**
        * @brief 用户自定义声学包数据到hdf5
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  UserDefTreatments    用户自定义声学包数据
        * @author yangjing (1195810980@qq.com)
        * @date 2025-1-2
        */
        bool writeUserDefTreatments(H5::Group & NCTGroup, QList<Acoustics::FITKAcousticsAbsNCT*> UserDefTreatments);

        /**
        * @brief 读多层声学包hdf5到数据
        * @param @param[i]  NCTGroup hdf5组别
        * @param @param[i]  mager    声学包管理器
        * @author yangjing (1195810980@qq.com)
        * @date 2025-1-2
        */
        bool readTreatmentLayUps(H5::Group & NCTGroup, Acoustics::FITKAcousticsNCTManager* mager);


        /**
        * @brief 读hdf5多层声学包一层数据到多层声学包
        * @param @param[i]  newObjectP 声学包类
        * @param @param[i]  NctType    层类型
        * @param @param[i]  layGroup   该层hdf5Group
        * @param @param[i]  lay       该层是第几层
        * @author yangjing (1195810980@qq.com)
        * @date 2025-1-2
        */
        bool readTreatmentLayUpsLay(Acoustics::FITKAcousticsNCTLayUp* newObjectP, Acoustics::FITKAcousticsNCTAbstractLayObj::NCTLayUpType NctType, H5::Group &layGroup, int lay);

        /**
        * @brief 写多层声学包数据到hdf5
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  TreatmentLayUps    多层声学包数据
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-31
        */
        bool writeTreatmentLayUps(H5::Group & NCTGroup, QList<Acoustics::FITKAcousticsAbsNCT*> TreatmentLayUps);

        /**
        * @brief 写多层声学包数据中的一层数据
        * @param @param[i]  group hdf5组别
        * @param @param[i]  lobj      该层的数据（基类）
        * @param @param[i]  layer     该层层号
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-31
        */
        bool writewriteTreatmentLayUpsLay(H5::Group &group, Acoustics::FITKAcousticsNCTAbstractLayObj* lobj, int layer);



        /**
        * @brief 将PerforationType转换为str
        * @param @param[i]  type 类型
        * @author yangjing (1195810980@qq.com)
        * @date 2025-1-2
        */
        QString PerforationToStr(Acoustics::FITKAcousticsNCTPerforated::PerforationType type);

        /**
        * @brief 将str转换为PerforationType
        * @param @param[i]  type 字符串
        * @author yangjing (1195810980@qq.com)
        * @date 2025-1-2
        */
        Acoustics::FITKAcousticsNCTPerforated::PerforationType StrFromPerforation(QString type);


        /**
        * @brief 将NCTLayUpType转换为str
        * @param @param[i]  type 类型
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-31
        */
        QString NCTLayUpTypeToStr(Acoustics::FITKAcousticsNCTAbstractLayObj::NCTLayUpType type);

        /**
        * @brief 将str转换为NCTLayUpType
        * @param @param[i]  type 字符串
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-31
        */
        Acoustics::FITKAcousticsNCTAbstractLayObj::NCTLayUpType StrFromNCTLayUpType(QString type);

        /**
        * @brief 将NCTSolidType转换为str
        * @param @param[i]  type 类型
        * @author yangjing (1195810980@qq.com)
        * @date 2025-1-2
        */
        QString NCTSolidTypeToStr(Acoustics::FITKAcousticsNCTPerforated::NCTSolidType type);

        /**
        * @brief 将str转换为NCTSolidType
        * @param @param[i]  type 字符串
        * @author yangjing (1195810980@qq.com)
        * @date 2025-1-2
        */
        Acoustics::FITKAcousticsNCTPerforated::NCTSolidType StrFromNCTSolidType(QString type);


    private:
        bool areAllTrue(const std::vector<bool>& Data)
        {
            return std::all_of(Data.begin(), Data.end(), [](bool b) { return b; });
        }

    private:
        IO::FITKHDF5FileTool*m_toolp{ nullptr };
    };
    Register2FITKIOAdaptorFactory(FITKAcousticsHDF5, Acoustics::FITKAcousticsNCTManager, FITKAcousticsNCTMgrAdaptor);
}
#endif
